package org.cyz.tools.core.assembly.log;

import java.text.SimpleDateFormat;

/**
 * Copyright (C), 2021
 * FileName: Log
 * Author:   chenyz
 * Date:     2021/12/31 PM2:35
 * Description: 日志
 */
public class Log {
    //文字颜色
    public static final String ANSI_RESET = "\u001B[0m";
    public static final String ANSI_BLACK = "\u001B[30m";
    public static final String ANSI_RED = "\u001B[31m";
    public static final String ANSI_GREEN = "\u001B[32m";
    public static final String ANSI_YELLOW = "\u001B[33m";
    public static final String ANSI_BLUE = "\u001B[34m";
    public static final String ANSI_PURPLE = "\u001B[35m";
    public static final String ANSI_CYAN = "\u001B[36m";
    public static final String ANSI_WHITE = "\u001B[37m";


    //如果您希望将文本的背景色更改为其他颜色，也可以尝试以下操作：
    public static final String ANSI_BLACK_BACKGROUND = "\u001B[40m";
    public static final String ANSI_RED_BACKGROUND = "\u001B[41m";
    public static final String ANSI_GREEN_BACKGROUND = "\u001B[42m";
    public static final String ANSI_YELLOW_BACKGROUND = "\u001B[43m";
    public static final String ANSI_BLUE_BACKGROUND = "\u001B[44m";
    public static final String ANSI_PURPLE_BACKGROUND = "\u001B[45m";
    public static final String ANSI_CYAN_BACKGROUND = "\u001B[46m";
    public static final String ANSI_WHITE_BACKGROUND = "\u001B[47m";

    private static final SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    public static void info(String className,Object log) {
        String info=String.format("%s %s [%s] - %s",ANSI_CYAN,sdf.format(System.currentTimeMillis()),className,log);
        System.out.println(info);
    }
    public static void info(String className,String log) {
        String info=String.format("%s %s [%s] - %s",ANSI_CYAN,sdf.format(System.currentTimeMillis()),className,log);
        System.out.println(info);
    }

    public static void info(String clasName,String log, String ...params) {
        log=String.format(log,params);
        String info=String.format("%s %s [%s] - %s",ANSI_PURPLE,sdf.format(System.currentTimeMillis()),clasName,log);
        System.out.println(info);
    }

    public static void info(String clasName,Object log, Object ...params) {
        log=String.format((String) log,params);
        String info=String.format("%s %s [%s] - %s",ANSI_PURPLE,sdf.format(System.currentTimeMillis()),clasName,log);
        System.out.println(info);
    }

    public static void error(String className, String message) {
        String info=String.format("%s %s [%s] - %s",ANSI_CYAN,sdf.format(System.currentTimeMillis()),className,message);
        System.err.println(info);
    }

    public static void error(String clasName,Object log, Object ...params) {
        log=String.format((String) log,params);
        String info=String.format("%s %s [%s] - %s",ANSI_PURPLE,sdf.format(System.currentTimeMillis()),clasName,log);
        System.err.println(info);
    }
}
